

<?php
if ($this->code == "0"){
    echo "<legend>";
    echo $this->msg;
    echo "</legend>";
}else echo $this->msg;

if (is_null($this->code) || ($this->code == "0" && $this->step == 1)){
?>

<legend>Bayar Tagihan Telepon/Seluler/PLN</legend>
<div class="row clearfix">
<div class="col-md-8 column">

    <?php
    if (is_null($this->code)){
    ?>

    <form method="post" id="frm" name="frm">
  
                <!-- Member form -->

                
                <?php //echo $this->today; ?>
                
                <h4>Data Pembayaran:</h4>
                
                <!-- fromAcc input-->
                <div class="form-group">
                    <label class="control-label">Dari Rekening</label>
                    
                        <select id="fromAcc" name="fromAcc" class="form-control">
                            <?php
                            
                           foreach ($this->accountList as $oAcc) {
                                    echo "<option value='".$oAcc['bank_account_no']."'>". $oAcc['bank_name'] .' '. $oAcc['bank_account_no'] ." (". $oAcc['account_name'] .")</option>";
                           }
                           ?>
                        </select>
                        <p class="help-block"></p>
                    
                </div>
                <br>
                <h4>Untuk Pembayaran:</h4>

                <!-- pay_for input-->
                <div class="form-group">
                    
                        <select id="pay_for" name="pay_for" class="form-control" required>
                            <option value=''>== Pilih Pembayaran ==</option>
                            <option value='TEL'>Telepon</option>
                            <option value='SPEEDY'>Speedy</option>
                            <option value='FLEXI'>Flexi</option>
                            <option value='PLN'>PLN</option>
                        </select>
                        <p class="help-block"></p>

                </div>

                <!-- from_list input-->
                <div class="form-group">
                    <label class="control-label"><input type="radio" id="fromRadio" name="fromRadio" value="1" onclick="pilihRek(this)"/> Dari Daftar Pribadi</label>
                    
                        <select id="from_list" name="from_list" class="form-control" disabled required>
                           <option value=''>== Pilih Daftar Pribadi ==</option>
                            <?php
                           //foreach ($this->accPersonalList as $oAcc) {
                             //       echo "<option value='".$oAcc['phone_num']."'>". $oAcc['phone_num'] ."</option>";
                           //}
                           ?>
                        </select>
                        <p class="help-block"></p>
                    
                </div>

   

                <!-- no_phonecell input-->
                <div class="form-group">                    
                        <label class="control-label"><input type="radio" id="fromRadio" name="fromRadio" value="2" onclick="pilihRek(this)"/> Isi Nomor Telepon/Seluler/PLN</label>
                        <input id="no_phonecell" name="no_phonecell" type="text" placeholder="Nomor Telepon/Seluler/PLN"
                        class="form-control" disabled required>
                        <p class="help-block">Pastikan No. Telepon/Seluler/PLN yang Anda masukan benar. Transaksi yang telah dikirim tidak dapat dibatalkan.</p>
                    
                </div>

               
                <!-- saveAs input-->
                <div class="form-group">
                        <label class="control-label"><input type="checkbox" id="cbSave" name="cbSave" disabled onchange="klikSave(this)"/> Simpan dalam daftar pribadi</label>
                        <input id="saveAs" name="saveAs" type="text" placeholder="Simpan Sebagai"
                        class="form-control" disabled required>
                        <p class="help-block"></p>
                </div>

                <!-- remark input-->
                <div class="form-group">
                    
                    <div class="controls">
                        <textarea id="remark" name="remark" type="text" placeholder="Catatan"
                        class="form-control"></textarea>
                        
                        <p class="help-block"></p>
                    </div>
                </div>

                <!-- submit btn-->
                <div class="form-group">
                    <label class="control-label"></label>
                    <div class="controls">
                        <input type="hidden" name="act" id="act" value="TAG">
                        <button class="btn btn-default" type="submit" id="btnSubmit" name="btnSubmit">
                        Lanjutkan</button> <div id="div_result"></div>
                        <p class="help-block"></p>
                    </div>
                </div>

        </form>
    <?php

    }else{
    ?>
        <form method="post" id="frm" name="frm">

                <!-- Member form -->


                <h4>Data Pembayaran:</h4>

                <!-- fromAcc input-->
                <div class="form-group">
                    <label class="control-label">Dari Rekening</label>

                    <select id="fromAccx" name="fromAccx" class="form-control" disabled>
                            <?php
                           $acc = "";
                           foreach ($this->accountList as $oAcc) {
                                    $acc = $oAcc['bank_account_no'];
                                    echo "<option value='".$oAcc['bank_account_no']."'>". $oAcc['bank_name'] .' '. $oAcc['bank_account_no'] ." (". $oAcc['account_name'] .")</option>";
                           }
                           ?>
                        </select>
                        <input type="hidden" name="fromAcc" id="fromAcc" value="<?php echo $acc;?>">
                        <p class="help-block"></p>

                </div>
                <br>
                <h4>Untuk Pembayaran:</h4>

                <!-- pay_for input-->
                <div class="form-group">

                        <select id="pay_forx" name="pay_forx" class="form-control" disabled>
                            <option value=''>== Pilih Pembayaran ==</option>
                            <option value='TEL' <?php echo ($this->formData['pay_for'] == 'TEL' ? "selected" : "") ?>>Telepon</option>
                            <option value='SPEEDY' <?php echo ($this->formData['pay_for'] == 'SPEEDY' ? "selected" : "") ?>>Speedy</option>
                            <option value='FLEXI' <?php echo ($this->formData['pay_for'] == 'FLEXI' ? "selected" : "") ?>>Flexi</option>
                            <option value='PLN' <?php echo ($this->formData['pay_for'] == 'PLN' ? "selected" : "") ?>>PLN</option>
                        </select>
                        <input type="hidden" name="pay_for" id="pay_for" value="<?php echo $this->formData['pay_for']?>">
                        <p class="help-block"></p>

                </div>

                

                <!-- no_phonecell input-->
                <div class="form-group">
                        <label class="control-label">Nomor Telepon/Seluler/PLN</label>
                        <input id="no_phonecellx" name="no_phonecellx" type="text" value="<?php echo $this->formData['idPelanggan']?>"
                        class="form-control" disabled>

                        <input id="no_phonecell" name="no_phonecell" type="hidden" value="<?php echo $this->formData['idPelanggan']?>">
                        

                </div>

                <!-- nama_pelanggan input-->
                <div class="form-group">
                        <label class="control-label">Nama Pelanggan</label>
                        <input id="nama_pelanggan" name="nama_pelanggan" type="text" value="<?php echo $this->data->namapelanggan;?>"
                        class="form-control" disabled>
                </div>

                <!-- jml_tagihan input-->
                <div class="form-group">
                        <label class="control-label">Jumlah Tagihan</label>
                        <input id="jml_tagihan" name="jml_tagihan" type="text" value="<?php echo number_format($this->data->jumlahtagihan, 2);?>"
                        class="form-control" disabled>
                </div>

                <!-- jml_adm input-->
                <div class="form-group">
                        <label class="control-label">Biaya Administrasi</label>
                        <input id="jml_adm" name="jml_adm" type="text" value="<?php echo number_format($this->data->jumlahadm, 2);?>"
                        class="form-control" disabled>
                </div>

                <!-- jml_bayar input-->
                <div class="form-group">
                        <label class="control-label">Jumlah Pembayaran</label>
                        <input id="jml_bayar_rp" name="jml_bayar_rp" type="text" value="<?php echo number_format($this->data->jumlahbayar, 2);?>"
                        class="form-control" disabled>
                        <input type="hidden" name="jml_bayar" id="jml_bayar" value="<?php echo $this->data->jumlahbayar;?>">
                </div>

                <!-- remark input-->
                <div class="form-group">

                    <label class="control-label">Catatan</label>
                        <textarea id="remark" name="remark" type="text" placeholder="Catatan"
                        class="form-control"><?php echo $this->formData['remark']?></textarea>

                        <p class="help-block"></p>
                    
                </div>

                <!-- submit btn-->
                <div class="form-group">
                    <label class="control-label"></label>
                    <div class="controls">
                        <input type="hidden" name="act" id="act" value="PAY">
                        <button class="btn btn-default" type="submit" id="btnSubmit" name="btnSubmit">
                        Submit</button> <div id="div_result"></div>
                        <p class="help-block"></p>
                    </div>
                </div>

        </form>
    <?php
    }
    ?>
</div>
</div>

        <script>

        $("select#pay_for").change(function(){
             var pf = $("#pay_for").val();
             var options = '';
             options += '<option value="">== Loading Daftar Pribadi ==</option>';
             $("select#from_list").html(options);
             //$("select#from_list").attr('disabled','disabled');

             $.getJSON("<?php echo $this->baseUrl() ?>/jsondata/daftarpribadi",{pay_for: pf, ajax: 'true'}, function(j){
                  options = '';
                  options += '<option value="">== Pilih Daftar Pribadi ==</option>';
                  for (var i = 0; i < j.length; i++) {
                    options += '<option value="' + j[i].phone_num + '">' + j[i].phone_num +' - '+ j[i].trans_name + '</option>';
                  }
                  //$("select#from_list").removeAttr('disabled');
                  $("select#from_list").html(options);
            })
          });


        function pilihRek(obj){

            if (obj.value == "1"){
                $("#from_list").removeAttr('disabled');

                $("#no_phonecell").val('');
                $("#no_phonecell").attr('disabled','disabled');


                $("#cbSave").removeAttr('checked');
                $("#cbSave").attr('disabled','disabled');

            }else{

                $("#from_list").attr('disabled','disabled');

                $("#no_phonecell").removeAttr('disabled');
                $("#cbSave").removeAttr('disabled');
                
            }
        }

        function klikSave(obj){
            if(obj.checked){
                $("#saveAs").removeAttr('disabled');
            }else{
                $("#saveAs").val('');
                $("#saveAs").attr('disabled','disabled');
            }
        }

        function validateNumber(evt) {

            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;
            return true;
          }

        /* Attach a submit handler to the form */
        $("#frm").submit(function(event) {

            /* Stop form from submitting normally */
            event.preventDefault();

            /* Clear result div*/
            $("#div_result").html('');
            $("#btnSubmit").html('Memproses...');
            $("#btnSubmit").attr('disabled','disabled');

            /* Get some values from elements on the page: */
            var values = $(this).serialize();
            var msg = [];
            
            /* Send the data using post and put the results in a div */

            $.ajax({
                url: "<?php echo $this->baseUrl() ?>/purchase/cellphonepay/",
                type: "post",
                data: values,
                success: function(response, opts){
                    <?php
                    if ($this->code == ""){
                    ?>
                    //var cekSess = response.toUpperCase().search("SESSION TIMEOUT");

                    //if (cekSess < 0){
                        //var cekStatus = response.toUpperCase().search("ERROR");

                        //if (cekStatus < 0){
                            $("#div_content").html(response);
                            location.href='#div_content';
                        /*
                        }else{
                            var resp = response.replace('ERROR', '');

                            msg.push('<span>'+resp+'</span>');
                            $.messager.alert('Info', msg.join('<br/>'));

                            //$("#div_result").html(resp);
                            $("#btnSubmit").removeAttr('disabled');
                            $("#btnSubmit").html('Submit');
                        }
                        */
                    /*
                    }else{
                        location.href='<?php echo $this->baseUrl() ?>/index/login/msg/Session Timeout silahkan login kembali !';
                    }
                    */
                   <?php
                    }else{
                   ?>
                    var cekSess = response.toUpperCase().search("SESSION TIMEOUT");

                    if (cekSess < 0){
                        var cekStatus = response.toUpperCase().search("ERROR");

                        if (cekStatus < 0){
                            $("#div_content").html(response);
                            location.href='#div_content';

                        }else{
                            var resp = response.replace('ERROR', '');

                            msg.push('<span>'+resp+'</span>');
                            $.messager.alert('Info', msg.join('<br/>'));

                            //$("#div_result").html(resp);
                            $("#btnSubmit").removeAttr('disabled');
                            $("#btnSubmit").html('Submit');
                        }


                    }else{
                        location.href='<?php echo $this->baseUrl() ?>/index/login/msg/Session Timeout silahkan login kembali !';
                    }
                    
                   <?php
                   }
                   ?>
                },
                error:function(response, opts){
                    //alert("failure");
                    msg.push('<span>'+response+'</span>');
                    $.messager.alert('Info', msg.join('<br/>'));

                    $("#btnSubmit").removeAttr('disabled');
                    $("#btnSubmit").html('Submit');
                }
            });

        });

        </script>

        <?php } ?>
    